module Hexena.Text.DrawGraph
  ( drawLine
  , drawHist
  ) where

import Data.Array.Unboxed
import Data.Word
import Graphics.UI.SDL
import Graphics.UI.SDL.Primitives

drawLine :: Surface -> Word32 -> Int -> Word8 -> Int -> IO Bool
drawLine s c maxHeight x y = vLine s x' maxHeight' (maxHeight' + y') $ Pixel c
    where x' = 7 + fromIntegral x
          y' = fromIntegral y
          maxHeight' = fromIntegral maxHeight

-- | Draw multiple lines given a surface two colours ("line" and
-- | "fill") and the starting X and Y positions.
drawHist :: Surface -> Word32 -> Word32 -> Int -> Int -> [Int] -> IO ()
drawHist s c1 c2 x y zs = mapM_ (uncurry fDraw) $ zip [x..] ys
    where vLine' x' y1 y2 = do
            vLine s (fromIntegral x') (fromIntegral y1) (fromIntegral y2) $ Pixel c2
            pixel s (fromIntegral x') (fromIntegral y2) $ Pixel c1
          ys = map ((+) y . negate) zs
          fDraw x' = vLine' x' y


-- displayHistoryGraph :: String -> UArray Word8 Int -> UArray Word8 Int -> Surface -> IO ()
-- displayHistoryGraph f h1 h2 display = do
--   let disform = surfaceGetPixelFormat display
--   fillRect display Nothing =<< mapRGB disform 0xff 0xff 0xff
--   drawHist display 0x5555a3ff 0x000080ff 7 64 $ elems h1'
--   drawHist display 0x55A555ff 0x006010ff 7 66 $ elems h2'
--     where h1' = scaleHist h1 id
--           h2' = scaleHist h2 negate


